package cn.kgm.makeGodV2.condition;

import cn.kgm.makeGodV2.emotion.PersonalityTrait;
import lombok.Builder;
import lombok.Data;

/**
 * 性格标签条件表达式处理器
 * @Version 1.8
 * @Author: Kappi
 * @Date: 2025-9-16 11:29
 * @Description: cn.kgm.makeGodV2.condition.TraitRangeCondition
 */
@Data
@Builder
public class TraitRangeCondition implements Condition {
    private String trait;
    private Double minValue;
    private Double maxValue;
    private boolean inclusiveMin = true;
    private boolean inclusiveMax = true;

    public TraitRangeCondition(String trait, Double minValue, Double maxValue) {
        this.trait = trait;
        this.minValue = minValue;
        this.maxValue = maxValue;
    }

    public TraitRangeCondition(String trait, Double minValue, Double maxValue,
                               boolean inclusiveMin, boolean inclusiveMax) {
        this(trait, minValue, maxValue);
        this.inclusiveMin = inclusiveMin;
        this.inclusiveMax = inclusiveMax;
    }

    @Override
    public boolean evaluate(PersonalityTrait traits) {
        double value = getTraitValue(traits, trait);

        boolean minCondition = (minValue == null) ||
                (inclusiveMin ? value >= minValue : value > minValue);

        boolean maxCondition = (maxValue == null) ||
                (inclusiveMax ? value <= maxValue : value < maxValue);

        return minCondition && maxCondition;
    }

    private double getTraitValue(PersonalityTrait traits, String trait) {
        switch (trait.toLowerCase()) {
            case "openness":
                return traits.getOpenness();
            case "conscientiousness":
                return traits.getConscientiousness();
            case "extraversion":
                return traits.getExtraversion();
            case "agreeableness":
                return traits.getAgreeableness();
            case "neuroticism":
                return traits.getNeuroticism();
            default:
                return 0;
        }
    }
}
